package com.demo.spring.controller;

import com.demo.spring.model.User;
import com.demo.spring.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/addop")
    public String add(Model model) {
        User user = new User();
        user.setAge(21);
        user.setName("张三");
        user.setPassword("123456");
        userService.add(user);
        model.addAttribute("tip", "用户添加成功");
        return "success";
    }

    @RequestMapping("/add")
    public String page() {
        return "add";
    }
}
